package com.zlict.admin.controller;

import com.zlict.admin.domain.ProjectApproval;
import com.zlict.admin.service.IProjectApprovalService;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.core.page.TableDataInfo;
import com.zlict.common.enums.BusinessType;
import com.zlict.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目立项信息Controller
 * 
 * @author dzw
 */
@RestController
@RequestMapping("/admin/approval")
public class ProjectApprovalController extends BaseController
{
    @Autowired
    private IProjectApprovalService projectApprovalService;

    /**
     * 查询项目立项信息列表
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:list')")
    @GetMapping("/list")
    public TableDataInfo list(ProjectApproval projectApproval)
    {
        startPage();
        List<ProjectApproval> list = projectApprovalService.selectProjectApprovalList(projectApproval);
        return getDataTable(list);
    }

    /**
     * 导出项目立项信息列表
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:export')")
    @Log(title = "项目立项信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProjectApproval projectApproval)
    {
        List<ProjectApproval> list = projectApprovalService.selectProjectApprovalList(projectApproval);
        ExcelUtil<ProjectApproval> util = new ExcelUtil<>(ProjectApproval.class);
        util.exportExcel(response, list, "项目立项信息数据");
    }

    /**
     * 获取项目立项信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:query')")
    @GetMapping(value = "/id/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(projectApprovalService.selectProjectApprovalById(id));
    }


    /**
     * 获取项目立项信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:query')")
    @GetMapping(value = "/projectId/{projectId}")
    public AjaxResult getInfoByProjectId(@PathVariable("projectId") Long projectId)
    {
        return success(projectApprovalService.selectProjectApprovalByProjectId(projectId));
    }

    /**
     * 新增项目立项信息
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:add')")
    @Log(title = "项目立项信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProjectApproval projectApproval)
    {
        return toAjax(projectApprovalService.insertProjectApproval(projectApproval));
    }

    /**
     * 修改项目立项信息
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:edit')")
    @Log(title = "项目立项信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProjectApproval projectApproval)
    {
        return toAjax(projectApprovalService.updateProjectApproval(projectApproval));
    }

    /**
     * 删除项目立项信息
     */
    @PreAuthorize("@ss.hasPermi('admin:approval:remove')")
    @Log(title = "项目立项信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(projectApprovalService.deleteProjectApprovalByIds(ids));
    }
}
